home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / pluginmanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-09-20  |  7.3 KB  |  220 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #ifndef _PLUGIN_MANAGER_
  8. #define _PLUGIN_MANAGER_
  9.  
  10. #include <QObject>
  11. #include <QString>
  12. #include <QMap>
  13.  
  14. class QEvent;
  15.  
  16. #include "scribusapi.h"
  17.  
  18. class ScribusDoc;
  19. class ScribusMainWindow;
  20. class ScPlugin;
  21. class ScActionPlugin;
  22. class ScPersistentPlugin;
  23. class PrefsContext;
  24.  
  25. /**
  26.  * \brief PluginManager handles plugin loading, unloading, and running.
  27.            *
  28.            * It contains methods and attributes for plugin running and its settings
  29.            * and returning values.
  30.            *
  31.            * Derived from Franz's ScribusMainWindow stuff (petr vanek)
  32.            *
  33.  */
  34. class SCRIBUS_API PluginManager : public QObject
  35. {
  36.  
  37.     Q_OBJECT
  38.  
  39. public:
  40.  
  41.     PluginManager();
  42.     ~PluginManager();
  43.  
  44.     /*! \brief Static methods for loading, unloading plugins and resolving symbols
  45.      These methods are platform independent, but each platform uses a different
  46.      implementation. */
  47.     static void* loadDLL( QString plugin );
  48.     static void* resolveSym( void* plugin, const char* sym );
  49.     static void  unloadDLL( void* plugin );
  50.  
  51.     /*! \brief Initalization of all plugins. It's called at scribus start.
  52.      *
  53.      * Walk through all plugins, try to init them and try to re-load failed
  54.      * ones then. See initPlugin for more info.
  55.      * Reload uses a "brute force" method - Repeat until there is something
  56.      * to load again. It's not elegant I know. But there are no additional
  57.      * dependancy relations addons (XML config, plugin classes change etc.).
  58.      */
  59.     void initPlugs();
  60.  
  61.     /*! \brief Called at after initPlugs to hook the loaded plugin into the GUI.
  62.      * Run in main window startup
  63.      */
  64.     bool setupPluginActions(ScribusMainWindow*);
  65.  
  66.     /*! \brief Called when the last doc is closed
  67.      */
  68.     void enableOnlyStartupPluginActions(ScribusMainWindow*);
  69.     /*! \brief Called when the last doc is closed
  70.      */
  71.     void enablePluginActionsForSelection(ScribusMainWindow*);
  72.  
  73.     /*! \brief Checks if is the plugin is in the plugin map, is loaded, and is enabled.
  74.      *
  75.      * \param pluginName name of plugin to get
  76.      * \param includeDisabled return true if a plugin is loaded but not enabled
  77.      * \return bool
  78.      */
  79.     bool DLLexists(QString pluginName, bool includeDisabled = false) const;
  80.  
  81.     /*! \brief Returns a pointer to the requested plugin, or 0 if not found.
  82.      *
  83.      * If includeDisabled is true, plugins that are loaded but not enabled
  84.      * are returned. If it is false, 0 is returned if the requested plugin
  85.      * is loaded but not enabled.
  86.      */
  87.     ScPlugin* getPlugin(const QString & pluginName, bool includeDisabled) const;
  88.  
  89.     /*! \brief Shutdowns all plugins. Called at scribus quit */
  90.     void cleanupPlugins();
  91.  
  92.     /** \brief Saves pluginManager preferences */
  93.     void savePreferences();
  94.  
  95.     /*! \brief Return file extension used for shared libs on this platform */
  96.     static QString platformDllExtension();
  97.  
  98.     /*! \brief Return file extension used for shared libs on this platform */
  99.     static int platformDllSearchFlags();
  100.  
  101.     /*! \brief Return a pointer to this instance.
  102.      \note for now, returns a reference to (*ScMW->pluginManager); should
  103.      probably be turned into a singleton later. */
  104.     static PluginManager & instance();
  105.  
  106.     /*! \brief Return the path to the file for the named plugin.
  107.     An invalid plugin name is an error.*/
  108.     const QString getPluginPath(const QString & pluginName) const;
  109.  
  110.     /*! \brief Whether the given plug-in will be enabled on start-up.
  111.     Usable as an lvalue. An invalid plugin name is an error. */
  112.     bool & enableOnStartup(const QString & pluginName);
  113.  
  114.     /*! \brief Whether the given plugin is currently enabled */
  115.     bool enabled(const QString & pluginName);
  116.  
  117.     /** \brief Return a list of plugin names currently known.
  118.      *
  119.      * If includeNotLoaded is true, names are returned for plug-ins that are
  120.      * not loaded (ie we have no ScPlugin instance for them).
  121.      *
  122.      * \param includeDisabled  Should the names of plugins that are loaded, but
  123.      *                         disabled, be returned?
  124.      * \param inherits         Only return plugins that inherit from this parent
  125.      *                         (the text name of the type - uses QMetaObject).
  126.      * \return A list of internal plugin names suitable for use with getPlugin etc.
  127.      *
  128.      * \sa getPluginNamesT
  129.      * \sa getPlugin
  130.      */
  131.     QStringList pluginNames(bool includeDisabled = false,
  132.                                      const char* inherits = 0) const;
  133.     
  134.     virtual void changeEvent(QEvent *e);
  135.  
  136. public slots:
  137.  
  138.     void languageChange();
  139.  
  140. protected:
  141.  
  142.     /**
  143.      * \brief PluginData is structure for plugin related informations.
  144.      * \param pluginFile path to the share library (with name).
  145.      * \param pluginName internal name of plug-in, used for prefix to dlsym() names
  146.      * \param pluginDLL reference to plug-in data for dynamic loading
  147.      * \param plugin is the pointer to the plugin instance
  148.      * \param enableOnStartup enable or disable plugin at app start-up
  149.      * \param enabled has the plug-in been set up and activated (gui connected, setup called, etc)?
  150.      *
  151.      * Note that there are some constraints on this structure.
  152.      * enabled == true depends on:
  153.      *     plugin != 0 which depends on:
  154.      *         pluginDLL != 0
  155.      *
  156.      * In other words, a plugin cannot be enabled unless we have an ScPlugin
  157.      * instance for it. We can't have an ScPlugin instance for a plugin unless
  158.      * it's linked.
  159.      */
  160.     struct PluginData
  161.     {
  162.         QString pluginFile; // Datei;
  163.         QString pluginName;
  164.         void* pluginDLL;
  165.         ScPlugin* plugin;
  166.         bool enableOnStartup;
  167.         bool enabled;
  168.     };
  169.  
  170.     /*! \brief Init one plugin.
  171.      * This method loadDLL(...)'s each plug-in, creates a Plugin instance for
  172.      * them, stores a PluginData for the plugin, sets up the plug-in's
  173.      * actions, and connects them to any required signals.
  174.      * It doesn't ask plug-ins to do any time-consuming setup.
  175.      * It's called by initPlugs.
  176.     \param fileName a filename of the plugin without path
  177.     \retval int 0 init failed, 1 loaded.
  178.      */
  179.     int initPlugin(const QString fileName);
  180.  
  181.     /*! \brief Reads available info and fills PluginData structure */
  182.     bool loadPlugin(PluginData & pluginData);
  183.  
  184.     /*! \brief Determines the plugin name from the file name and returns it. */
  185.     static QString getPluginName(QString fileName);
  186.  
  187.     /*! \brief Called by loadPlugin to hook the loaded plugin into the GUI,
  188.     call its setup routine, etc. Not responsible for creating
  189.     the ScPlugin instance or loading the plugin. */
  190.     void enablePlugin(PluginData &);
  191.  
  192.     /*! \brief Called by finalizePlug when shutting down a plug-in. Unhooks
  193.      the plug-in from the GUI, calls its cleanup routine, etc.
  194.      DOES NOT destroy the ScPlugin instance or unload the plugin. */
  195.     void disablePlugin(PluginData & pda);
  196.  
  197.     /*! \brief Runs plugin's languageChange() method, and returns main menu item text if one exists */
  198.     QString callDLLForNewLanguage(const PluginData & pluginData);
  199.  
  200.     /*! \brief Shuts down one plug-in. The DLL may not be unloaded, but
  201.      *         it is cleaned up and its ScPlugin instance is destroyed.
  202.      *         The plug-in is marked unloaded in the map.
  203.      *  \param pda plugin data
  204.      */
  205.     void finalizePlug(PluginData & pda);
  206.  
  207.     /** \brief Configuration structure */
  208.     PrefsContext* prefs;
  209.  
  210.     /*! \brief Mapping of plugin names to plugin info structures. */
  211.     typedef QMap<QString,PluginData> PluginMap;
  212.  
  213.     /*! \brief Plugin mapping.
  214.      * Each plugin has its record key() -> PluginData
  215.      */
  216.     PluginMap pluginMap;
  217. };
  218.  
  219. #endif
  220.